package com.lcm.learn.lcmcode.concurrent;

import java.util.Hashtable;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @description:
 * @author: lcm
 * @create: 2019-12-20 09:53
 **/

public class ConcurrentHashMapTest {

    /**
     * sizeCtl=-1初始化
     * sizeCtl<0,-(1+扩容线程数)
     */
    private transient volatile int sizeCtl;
    public static void main(String[] args){

        Hashtable hashtable=new Hashtable();
        hashtable.put(1,1);
        ConcurrentHashMap map=new ConcurrentHashMap(16);
        map.put(1,1);
        map.get(1);
        System.out.println(Integer.toBinaryString(-1));
        System.out.println(Integer.toBinaryString(Integer.numberOfLeadingZeros(16)));
        System.out.println(Integer.toBinaryString((1<<15)));
        System.out.println(Integer.toBinaryString(resizeStamp(16)));
        System.out.println(Integer.toBinaryString(resizeStamp(16)<<16));
        System.out.println(Integer.toBinaryString((resizeStamp(16)<<16)+2));
    }

    static final int resizeStamp(int n) {
        return Integer.numberOfLeadingZeros(n) | (1 << (16 - 1));
    }

}
